//
//  WTRecomendDetailViewController.m
//  OneDay
//
//  Created by lanou on 16/1/12.
//  Copyright © 2016年 小明. All rights reserved.
//

#import "WTRecomendDetailViewController.h"
#import "WTRequestManager.h"
#import "WTDetailHeadView.h"
#import "WTAboutNewsModel.h"
#import "WTRecommendDetailModel.h"
#import "WTCommentTableViewCell.h"
#import "WTCommentViewController.h"
#import <MBProgressHUD.h>
#import "WTInformationHandle.h"
#import <UMSocial.h>
#import <WebKit/WebKit.h>
#import <UMSocialWechatHandler.h>
#import <UMSocialQQHandler.h>



#define kHeadViewHeight 110 *  kRelativeLength_X

@interface WTRecomendDetailViewController ()<UITableViewDataSource,UITableViewDelegate,UIWebViewDelegate,UITextFieldDelegate,UITextViewDelegate>

// 创建webView
@property (nonatomic, strong) UIWebView *webView;

// 创建WTDetailHeadView
@property (nonatomic, strong) WTDetailHeadView *headView;

// 创建tableView
@property (nonatomic, strong) UITableView * tableView;

// 这个scrollView是用来拼接WTDetailHeadView 和webView 的
@property (nonatomic, strong) UIScrollView *scrollView;

// 热门推荐的数组
@property (nonatomic, strong) NSMutableArray * aboutNewsArray;
// 热门评论的数组
@property (nonatomic, strong) NSMutableArray * hotCommentArray;



// 标题
@property (nonatomic, strong) NSString * detailTitle;
// 作者名
@property (nonatomic, strong) NSString * authorNickName;
// 发布时间
@property (nonatomic, strong) NSString * publishTime;
// 评论人数
@property (nonatomic, strong) NSString * commentSum;
// 赞人数
@property (nonatomic, strong) NSString * laud;
// 踩
@property (nonatomic, strong) NSString * stamp;

// 分享链接
@property (nonatomic, strong) NSString * shareUrl;


// 视频的网址
@property (nonatomic, strong) NSString * videoUrlString;
// 等待网络加载完成
@property (nonatomic, strong) MBProgressHUD * hud;

// 表尾
@property (nonatomic, strong) UIView * tableFootView;

//-----------------底部评论等
// 有底部评论的视图
@property (nonatomic, strong) UIView * footView;

// 评论的文本框
@property (nonatomic, strong) UITextField * commentTF;
// 分享
@property (nonatomic, strong) UIButton * shareButton;
//-------------------------

// 键盘辅助视图
@property (nonatomic, strong) UIView * keyAssistView;

// 评论内容的textView
@property (nonatomic, strong) UITextView * contentTV;


// 计算的高度 -- 文字的高度
@property (nonatomic, assign) CGFloat heightText;


// 当评论时背景色为灰色
@property (nonatomic, strong) UIView * bgview;

@end

@implementation WTRecomendDetailViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.tabBarController.tabBar.hidden = YES;
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    self.view.backgroundColor = [UIColor whiteColor];
//    self.navigationController.navigationBar.barTintColor = [UIColor blueColor];
    // 去掉导航栏的透明色
//    self.navigationController.navigationBar.translucent = NO;
    
    [self setupData];
    
    // 取消系统对scrollView的自适应
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    // 创建WKWebView
    _webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, _headView.bottom, kScreenWidth, 0)];
    _webView.delegate = self;
    _webView.scrollView.bounces = NO;
    _webView.scrollView.showsHorizontalScrollIndicator = NO;
    // 设置webView不能滑动
    _webView.scrollView.scrollEnabled = NO;
    [_webView sizeToFit];
    
    
    // 创建headView
    _headView = [[WTDetailHeadView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kHeadViewHeight)];
    _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 200 * kRelativeLength_X)];
    _scrollView.bounces = NO;
    _scrollView.showsHorizontalScrollIndicator = NO;
    _scrollView.showsVerticalScrollIndicator = NO;
    _scrollView.scrollEnabled = NO;
  
    [_scrollView addSubview:_headView];
    // 初始化tableView
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, kScreenWidth, kScreenHeight - 64 - 49) style:(UITableViewStylePlain)];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    
    // 注册cell
    [_tableView registerClass:[WTCommentTableViewCell class] forCellReuseIdentifier:@"WTCommentTableViewCell"];
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];
    
#pragma mark -- 把scrollView作为tableView的表头
    _tableView.tableHeaderView = _scrollView;
    
    
#pragma mark -- tableView的表尾
    _tableFootView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 40 * kRelativelength_Y)];
    _tableFootView.backgroundColor = [UIColor whiteColor];
    UIButton * moreButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    moreButton.frame = CGRectMake((kScreenWidth - 100 * kRelativeLength_X) / 2, kRelativelength_Y * 10, 100 * kRelativeLength_X, 20 * kRelativelength_Y);
    [moreButton setTitle:@"更多评论" forState:(UIControlStateNormal)];
    [moreButton setTitleColor:[UIColor blueColor] forState:(UIControlStateNormal)];
    [moreButton addTarget:self action:@selector(moreCommentButton:) forControlEvents:(UIControlEventTouchUpInside)];
    [_tableFootView addSubview:moreButton];
    _tableView.tableFooterView = _tableFootView;
    
   

    // 创建多少个评论的按钮
    NSString * title = [NSString stringWithFormat:@"%@条评论",_commentNumber];
    UIBarButtonItem * rightButton = [[UIBarButtonItem alloc]initWithTitle:title style:(UIBarButtonItemStylePlain) target:self action:@selector(rightButtonClick:)];
    self.navigationItem.rightBarButtonItem = rightButton;
    
   
    _hotCommentArray = [NSMutableArray array];
    [self requestData];
    
    [self setupprogressHud];
   
    
    
   
    
    
    
    
#pragma mark -- 键盘监听
    // 增加监听,当键盘出现或改变时收出消息
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardDidShowNotification object:nil];
    // 增加监听,当键盘退出收出消息
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    // Do any additional setup after loading the view.
    
    
    //
    
}

#pragma mark -- 添加底部评论的视图
- (void)addFootView{
    
    _footView = [[UIView alloc]initWithFrame:CGRectMake(0, kScreenHeight - 49, kScreenWidth, 49)];
    _footView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_footView];
    
    
#pragma mark -- 键盘辅助视图
    _keyAssistView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 150 * kRelativelength_Y)];
    
    // 内容
    _contentTV = [[UITextView alloc]initWithFrame:CGRectMake(5 * kRelativeLength_X, 5 * kRelativelength_Y, kScreenWidth - 10 * kRelativeLength_X, 90 * kRelativelength_Y)];
    
    _contentTV.returnKeyType = UIReturnKeyNext;
    _contentTV.font = [UIFont systemFontOfSize:16];
    
    NSDictionary *dict=@{NSFontAttributeName:[UIFont systemFontOfSize:16]};
    CGSize contentSize = [@"我" sizeWithAttributes:dict];
    _heightText = contentSize.height;
    [_keyAssistView addSubview:_contentTV];
    
#pragma mark -- 发布按钮
    UIButton * publishCommentButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    publishCommentButton.frame = CGRectMake(kScreenWidth - 65 * kRelativeLength_X, _contentTV.bottom + 20 * kRelativelength_Y, 60 * kRelativeLength_X, 20 * kRelativelength_Y);
    publishCommentButton.backgroundColor = [UIColor grayColor];
    [publishCommentButton setTitle:@"发布" forState:(UIControlStateNormal)];
    [publishCommentButton addTarget:self action:@selector(publishCommentButtonClick:) forControlEvents:(UIControlEventTouchUpInside)];
    [_keyAssistView addSubview:publishCommentButton];
    
    
#pragma mark -- 评论的textField
    _commentTF = [[UITextField alloc]initWithFrame:CGRectMake(20 * kRelativeLength_X, (49 - 20 * kRelativelength_Y) / 2, 280 * kRelativeLength_X, 20 * kRelativelength_Y)];
    _commentTF.placeholder = @"我来说两句";
    _commentTF.delegate = self;
    _commentTF.borderStyle = UITextBorderStyleRoundedRect;
    _commentTF.clearsOnBeginEditing = YES;
    _commentTF.clearButtonMode = UITextFieldViewModeAlways;
    _commentTF.returnKeyType = UIReturnKeySend;
    _commentTF.inputAccessoryView = _keyAssistView;
    [_footView addSubview:_commentTF];
    
   
#pragma mark -- 分享按钮
    
    UIButton * shareButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    shareButton.frame = CGRectMake(_commentTF.right + 10 * kRelativeLength_X, _commentTF.top, 30 * kRelativeLength_X, _commentTF.height);
    [shareButton setBackgroundImage:[UIImage imageNamed:@"m-fenxiang"] forState:(UIControlStateNormal)];
    [shareButton addTarget:self action:@selector(shareButtonClick:) forControlEvents:(UIControlEventTouchUpInside)];
    [_footView addSubview:shareButton];
    
    
   
    
    
}

#pragma mark -- 分享的按钮
- (void)shareButtonClick:(UIButton *)sender{

      [UMSocialWechatHandler setWXAppId:@"wx2efc3516108c521f" appSecret:@"20ff141b8337683d3a92665e1000750d" url:_shareUrl];
      [UMSocialQQHandler setQQWithAppId:@"1105058057" appKey:@"hYD0bP3xKobtMo3O" url:_shareUrl];
      [UMSocialSnsService presentSnsIconSheetView:self appKey:@"56a041f0e0f55a55880002f5" shareText:[NSString stringWithFormat:@"%@          %@",_detailTitle,_shareUrl] shareImage:[UIImage imageNamed:@"icon.png"] shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToWechatSession,UMShareToWechatTimeline ,UMShareToQQ,nil] delegate:nil];
}

#pragma mark -- 发布评论的方法
- (void)publishCommentButtonClick:(UIButton *)sender{
  
    // act=feedback&aid=5303638&fid=&face=http%3A%2F%2Fimage.mier123.com%2Fapi%2Fimages%2Fpl_icon_default_head20.png&uid=1166815&versioncode=20150807&msg=%E6%97%A5%E6%9C%AC%E4%B9%9F%E5%8F%AA%E8%83%BD%E5%8F%AB%E5%9A%A3%E8%80%8C%E5%B7%B2&author=155****3531
    NSMutableDictionary * parDic = [NSMutableDictionary dictionary];
    parDic[@"act"] = @"feedback";
    parDic[@"aid"] = _ID;
    parDic[@"fid"] = @"";
    parDic[@"face"] = [WTInformationHandle shareInformationHandle].userImg;
    parDic[@"uid"] = [WTInformationHandle shareInformationHandle].ID;
    parDic[@"versioncode"] = @"20150807";
    parDic[@"msg"] = _contentTV.text;
    parDic[@"author"] = [WTInformationHandle shareInformationHandle].userName;
    
    [WTRequestManager requestWithUrlString:@"http://api.wap.miercn.com/api/2.0.3/feedback.php?plat=android&proct=mierapp&versioncode=20150807&apiCode=4" parDic:parDic method:POST success:^(NSData *data) {
    
        UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"评论成功" preferredStyle:(UIAlertControllerStyleAlert)];
        UIAlertAction * okAction = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault ) handler:nil];
        [alert addAction:okAction];
        [self presentViewController:alert animated:YES completion:nil];
        
    } error:^(NSError *error) {
        
    }];
    
}

// 当键盘出现或改变时调用
- (void)keyboardWillShow:(NSNotification *)aNotficatio{
   
    _bgview.hidden = NO;
    [_contentTV becomeFirstResponder];

}
//当键退出时调用
- (void)keyboardWillHide:(NSNotification *)aNotification
{
 
    _bgview.hidden = YES;
    
}

#pragma mark -- 在文本框内容发生变化时计算所有文字的长度,判断是否超过
-(void)textViewDidChange:(UITextView *)textView
{
    float currentLineNum=1;//默认文本框显示一行文字
    float textViewWidth=_contentTV.frame.size.width;//取得文本框高度
    NSString *content=textView.text;
    NSDictionary *dict=@{NSFontAttributeName:[UIFont systemFontOfSize:16]};
    CGSize contentSize=[content sizeWithAttributes:dict];//计算文字长度
    float numLine=ceilf(contentSize.width/textViewWidth); //计算当前文字长度对应的行数
    
    
    if(numLine>currentLineNum ){
        //如果发现当前文字长度对应的行数超过。 文本框高度，则先调整当前view的高度和位置，然后调整输入框的高度，最后修改currentLineNum的值
        _keyAssistView.frame=CGRectMake(_keyAssistView.left, _keyAssistView.top - _heightText*(numLine-currentLineNum), _keyAssistView.width, _keyAssistView.height+ _heightText*(numLine-currentLineNum));
        textView.frame=CGRectMake(textView.left, textView.top, textView.width, textView.height+_heightText*(numLine-currentLineNum));
        currentLineNum=numLine;
    }else if (numLine<currentLineNum ){
        //次数为删除的时候检测文字行数减少的时候
        _keyAssistView.frame=CGRectMake(_keyAssistView.left, _keyAssistView.top +_heightText*(currentLineNum-numLine),_keyAssistView.width, _keyAssistView.height-_heightText*(currentLineNum-numLine));
        textView.frame=CGRectMake(textView.left, textView.top, textView.width, textView.height-_heightText*(currentLineNum-numLine));
        currentLineNum=numLine;
    }
    
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{

    [textField resignFirstResponder];
    return YES;
}


// 更多评论的按钮
- (void)moreCommentButton:(UIButton *)button
{
    [self rightButtonClick:nil];
}

#pragma mark -- 等待网络完成
- (void)setupprogressHud
{
    _hud = [[MBProgressHUD alloc]initWithView:self.view];
    _hud.frame = self.view.bounds;
    _hud.minSize = CGSizeMake(100, 100);
    _hud.mode = MBProgressHUDModeIndeterminate;
    _hud.labelText = @"正在努力加载....";
    [self.view addSubview:_hud];
    
    [_hud show:YES];
    
}
#pragma mark -- rightButton 导航栏右侧按钮
- (void)rightButtonClick:(UIBarButtonItem *)button
{
    WTCommentViewController * commentVC = [[WTCommentViewController alloc]init];
    commentVC.ID = _ID;
    commentVC.hotCommentArray = _hotCommentArray;
    commentVC.commentNumber = _commentNumber;
    [self.navigationController pushViewController:commentVC animated:YES];
}


#pragma mark -- 评论的网络请求
- (void)requestData
{
    NSString * url = [NSString stringWithFormat:@"http://api.wap.miercn.com/api/2.0.3/feedback.php?act=get_list&aid=%@&page=1&plat=android&proct=mierapp&versioncode=20150807&apiCode=4",_ID];
   [WTRequestManager requestWithUrlString:url parDic:nil method:GET success:^(NSData *data) {
       
       NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
//   http://api.wap.miercn.com/api/2.0.3/feedback.php?act=get_list&aid=5196561&page=1&plat=android&proct=mierapp&versioncode=20150807&apiCode=4     
       // 解析热门评论
       NSArray * hotArray = dic[@"hotcommentList"];
       
       for (NSDictionary *oneDic in hotArray) {
           WTRecommendDetailModel *model = [[WTRecommendDetailModel alloc]init];
           [model setValuesForKeysWithDictionary:oneDic];
           [_hotCommentArray addObject:model];
       }
       [_tableView reloadData];
   } error:^(NSError *error) {
   }];
}

#pragma mark -- 网络请求
- (void)setupData
{
   
    _aboutNewsArray = [NSMutableArray array];
    NSString *url = [NSString stringWithFormat:@"http://api.wap.miercn.com/api/2.0.3/article_json.php?id=%@&plat=android&proct=mierapp&versioncode=20150807&apiCode=4",_ID];
   [WTRequestManager requestWithUrlString:url parDic:nil method:GET success:^(NSData *data) {
       
       NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
// ------------------- 解析数据,将相关新闻转化为model
       NSArray * aboutNewsArr = dic[@"aboutNews"];
       for (NSDictionary * dic in aboutNewsArr) {
           WTAboutNewsModel * model = [[WTAboutNewsModel alloc]init];
           [model setValuesForKeysWithDictionary:dic];
           [_aboutNewsArray addObject:model];
       }
       
       // 赋值
       _detailTitle = dic[@"title"];
       _authorNickName = dic[@"authorNickName"];
       _commentSum = dic[@"commentSum"];
       _publishTime = dic[@"publishTime"];
       _laud = dic[@"laud"];
       _stamp = dic[@"stamp"];
       _shareUrl = dic[@"shareUrl"];
       
       
       // 只有视频的点击进来后 有这个videoUrl的属性
       BOOL isVideo = NO;
       NSArray * keys = [dic allKeys];
       for (NSString * key in keys) {
           [key isEqualToString:@"videoUrl"];
           isVideo = YES;
           
       }
       if (isVideo == YES) {
           _videoUrlString = dic[@"videoUrl"];
       }
       
       NSString *webContent = dic[@"webContent"];
       ///////////////////////////////设置内容，这里包装一层div，用来获取内容实际高度（像素），htmlcontent是html格式的字符串//////////////
       webContent = [NSString stringWithFormat:@"<div id=\"webview_content_wrapper\">%@</div>", webContent];
       // 改变图片的大小
       webContent = [NSString stringWithFormat:@"<head><style>img{width:%fpx !important;}</style></head>%@",kScreenWidth - 20 * kRelativeLength_X,webContent];
       [_webView loadHTMLString:webContent baseURL:nil];
   } error:^(NSError *error) {
   }];
}

#pragma mark -- webView的代理方法
////////////////////////////////delegate的方法重载////////////////////////////////////////////
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    //获取页面高度（像素）
    NSString * clientheight_str = [webView stringByEvaluatingJavaScriptFromString: @"document.body.offsetHeight"];
    float clientheight = [clientheight_str floatValue];
    //设置到WebView上
    webView.frame = CGRectMake(0, 0, self.view.frame.size.width, clientheight);
    //获取WebView最佳尺寸（点）
    CGSize frame = [webView sizeThatFits:webView.frame.size];
    //获取内容实际高度（像素）
    NSString * height_str= [webView stringByEvaluatingJavaScriptFromString: @"document.getElementById('webview_content_wrapper').offsetHeight + parseInt(window.getComputedStyle(document.getElementsByTagName('body')[0]).getPropertyValue('margin-top')) + parseInt(window.getComputedStyle(document.getElementsByTagName('body')[0]).getPropertyValue('margin-bottom'))"];
    float height = [height_str floatValue];
    //内容实际高度（像素）* 点和像素的比
    height = height * frame.height / clientheight;
    //再次设置WebView高度（点）
    webView.frame = CGRectMake(0, _headView.bottom, self.view.frame.size.width, height);
    
 
    // 前面设置了scrollView不可以滑动,滑动的话会和tableView两者冲突. 所以我们设置scrollView的frame
    _scrollView.frame = CGRectMake(0, 0, kScreenWidth, height + _headView.height + 20 * kRelativelength_Y);
    [_scrollView addSubview:_webView];

    // 对scrollView的操作要放在之前,虽然之前把scrollView作为tableView的表头,但是之后再对scrollView操作的话就与tableView无关了
    _tableView.tableHeaderView = _scrollView;
    

#pragma mark -- headView的控件进行赋值
    _headView.titleLabel.text = _detailTitle;
    _headView.authorNameLabel.text = _authorNickName;

    
    // 将时间间隔转化为日期进行展示
    NSInteger interval = [_publishTime integerValue];
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:interval];
    NSString *dateString = [NSString stringWithFormat:@"%@",date];
    NSString *publish = [dateString substringToIndex:10];
    _headView.publishTimeLabel.text = publish;

#pragma mark -- 在这边进行tableView的刷新,是因为我们在网络请求进行刷新的话,会导致会出现展示数据完以后,webView加载完成
    [self.view addSubview:_tableView];
 
    // 停止转动
    [self.hud hide:YES];
    
#pragma mark -- 当评论时背景色为灰色,因为异步网络请求的问题,使得我们不能在上面添加这个视图的时候, 需要我们在刷新完成后添加
    _bgview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    _bgview.backgroundColor = [UIColor grayColor];
    _bgview.alpha = 0.8;
    _bgview.hidden = YES;
    [self.view addSubview:_bgview];
    [self addFootView];
    
    // 添加手势
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
    [_bgview addGestureRecognizer:tap];
    
    
    [_tableView reloadData];
    [self webViewDid:webView];
}
#pragma mark -- 手势的添加方法,使得键盘回收
- (void)tapAction:(UITapGestureRecognizer *)sender{

    

     [_contentTV resignFirstResponder];
    [self.view endEditing:YES];
    
    
}


// 在网页加载完成时，通过js获取图片和添加点击的识别方式
- (void)webViewDid:(UIWebView *)webView {
   
    
    //这里是js，主要目的实现对url的获取
    static  NSString * const jsGetImages =
    @"function getImages(){\
    var objs = document.getElementsByTagName(\"img\");\
    var imgScr = '';\
    for(var i=0;i<objs.length;i++){\
    imgScr = imgScr + objs[i].src + '+';\
    };\
    return imgScr;\
    };";
    
    [webView stringByEvaluatingJavaScriptFromString:jsGetImages];//注入js方法
    NSString *urlResurlt = [webView stringByEvaluatingJavaScriptFromString:@"getImages()"];
    NSMutableArray * mUrlArray = [NSMutableArray arrayWithArray:[urlResurlt componentsSeparatedByString:@"+"]];
    if (mUrlArray.count >= 2) {
        [mUrlArray removeLastObject];
    }
    //urlResurlt 就是获取到得所有图片的url的拼接；mUrlArray就是所有Url的数组
    
    //添加图片可点击js
    [_webView stringByEvaluatingJavaScriptFromString:@"function registerImageClickAction(){\
     var imgs=document.getElementsByTagName('img');\
     var length=imgs.length;\
     for(var i=0;i<length;i++){\
     img=imgs[i];\
     img.onclick=function(){\
     window.location.href='image-preview:'+this.src}\
     }\
     }"];
    [_webView stringByEvaluatingJavaScriptFromString:@"registerImageClickAction();"];
}

//在这个方法中捕获到图片的点击事件和被点击图片的url
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    
    //预览图片
    if ([request.URL.scheme isEqualToString:@"image-preview"]) {
     
        if (_videoUrlString != nil && ![_videoUrlString isEqualToString:@""]) {
            
            NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:_videoUrlString]];
            UIWebView * webView =  [[UIWebView alloc]initWithFrame:CGRectMake(100 * kRelativeLength_X, 150 * kRelativeLength_X, 200 * kRelativeLength_X, 200 * kRelativeLength_X)];
            webView.scrollView.scrollEnabled = NO;
            webView.scrollView.bounces = NO;
            [webView loadRequest:request];
            [_scrollView addSubview:webView];
            return NO;
        }else{
        
            return NO;
        }
    }else {
        return YES;
    }
    return YES;
}


//-(void) doubleTap :(UITapGestureRecognizer*) sender
//{
//    //  <Find HTML tag which was clicked by user>
//    //  <If tag is IMG, then get image URL and start saving>
//    int scrollPositionY = [[_webView stringByEvaluatingJavaScriptFromString:@"window.pageYOffset"] intValue];
//    int scrollPositionX = [[_webView stringByEvaluatingJavaScriptFromString:@"window.pageXOffset"] intValue];
//    
//    int displayWidth = [[_webView stringByEvaluatingJavaScriptFromString:@"window.outerWidth"] intValue];
//    CGFloat scale = _webView.frame.size.width / displayWidth;
//    
//    CGPoint pt = [sender locationInView:_webView];
//   NSLog(@"%.f,%.f",pt.x,pt.y);
//    pt.x *= scale;
//    pt.y *= scale;
//    pt.x += scrollPositionX;
//    pt.y += scrollPositionY;
//    
//   
//    
//    NSString *js = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).tagName", pt.x, pt.y];
//    NSString * tagName = [_webView stringByEvaluatingJavaScriptFromString:js];
//    if ([tagName isEqualToString:@"img"]) {
//        NSString *imgURL = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).src", pt.x, pt.y];
//        NSString *urlToSave = [_webView stringByEvaluatingJavaScriptFromString:imgURL];
//        NSLog(@"image url=%@", urlToSave);
//    }
//}


#pragma mark -- dataSource的代理方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return _aboutNewsArray.count;
    } else {
    
        return _hotCommentArray.count;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // 判断分区
    // 0分区代表是热门推荐
    // 1分区代表的精彩评论
    if (indexPath.section == 0) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell" forIndexPath:indexPath];
        WTAboutNewsModel * model = _aboutNewsArray[indexPath.row];
        cell.textLabel.text = model.title;
        return cell;
    }else {
        WTCommentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WTCommentTableViewCell" forIndexPath:indexPath];
        WTRecommendDetailModel *model = _hotCommentArray[indexPath.row];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        cell.model = model;
      
        return cell;
    }

 
}
// 返回分区标题
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return @"热门推荐";
    } else{
       return @"精彩评论";
    }
    
}



// 返回cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // indexPath.section == 1 代表的是评论,这里返回cell的高度
    if (indexPath.section == 1) {
        return [WTCommentTableViewCell heightForRowWithModel:_hotCommentArray[indexPath.row]];
    }
    return 30 * kRelativelength_Y;
}

#pragma mark -- cell的点击方法,重要是热门推荐的点击
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // 之后热门推荐可以点击跳转
    if (indexPath.section == 0) {
       
        WTRecomendDetailViewController *detaliVC = [[WTRecomendDetailViewController alloc]init];
        WTAboutNewsModel *model = _aboutNewsArray[indexPath.row];
        detaliVC.ID = model.ID;
        detaliVC.commentNumber = model.commentNum;
        [self.navigationController pushViewController:detaliVC animated:YES];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
